local tf_spicedfoods = require("tf_spicedfoods") -- 调味料理
local cooking = require("cooking")

-- 动作相关
AddStategraphPostInit("wilson", function(sg)
    -- 玩家拥有免僵直标签时被攻击不会僵直
    if sg.events and sg.events.attacked then
        local oldattackedfn = sg.events.attacked.fn
        sg.events.attacked.fn = function(inst, data)
            -- 这里顺便加个playerghost的判断，免得玩家濒死的时候又挨了一下揍报错
            if inst:HasTag("DurianCandy") or inst:HasTag("playerghost") then
                return
            elseif oldattackedfn then
                return oldattackedfn(inst, data)
            end
        end
    end

    -- 吃了蛋白粉的玩家背东西速度增快
    if sg.states.run_start then
        local oldonenter = sg.states.run_start.onenter
        sg.states.run_start.onenter = function(inst, ...)
            if inst.components.inventory:IsHeavyLifting() and inst:HasTag("tf_strong") and not (inst.components.rider and inst.components.rider:IsRiding()) then
                inst.sg.statemem.heavy_fast = true
                inst.components.locomotor:RunForward()
                inst.AnimState:PlayAnimation("heavy_walk_fast_pre")
                inst.sg.mem.footsteps = 0 -- (inst.sg.statemem.goose or inst.sg.statemem.goosegroggy) and 4 or 0
            elseif oldonenter then
                oldonenter(inst, ...)
            end
        end
    end
    if sg.states.run then
        local oldonenter = sg.states.run.onenter
        sg.states.run.onenter = function(inst, ...)
            if inst.components.inventory:IsHeavyLifting() and inst:HasTag("tf_strong") and not (inst.components.rider and inst.components.rider:IsRiding()) then
                inst.sg.statemem.heavy_fast = true
                inst.components.locomotor:RunForward()
                if not inst.AnimState:IsCurrentAnimation("heavy_walk_fast") then
                    inst.AnimState:PlayAnimation("heavy_walk_fast", true)
                end
                inst.sg:SetTimeout(inst.AnimState:GetCurrentAnimationLength() + .5 * FRAMES)
            elseif oldonenter then
                oldonenter(inst, ...)
            end
        end
    end
    if sg.states.run_stop then
        local oldonenter = sg.states.run_stop.onenter
        sg.states.run_stop.onenter = function(inst, ...)
            if inst.components.inventory:IsHeavyLifting() and inst:HasTag("tf_strong") and not (inst.components.rider and inst.components.rider:IsRiding()) then
                inst.sg.statemem.heavy_fast = true
                inst.components.locomotor:Stop()
                inst.AnimState:PlayAnimation("heavy_walk_fast_pst")
            elseif oldonenter then
                oldonenter(inst, ...)
            end
        end
    end
end)

-- 客户端当然也要处理啦
AddStategraphPostInit("wilson_client", function(sg)
    -- 吃了蛋白粉的玩家背东西速度增快
    if sg.states.run_start then
        local oldonenter = sg.states.run_start.onenter
        sg.states.run_start.onenter = function(inst, ...)
            if inst.replica.inventory:IsHeavyLifting() and inst:HasTag("tf_strong") and not (inst.replica.rider ~= nil and inst.replica.rider:IsRiding()) then
                inst.sg.statemem.heavy_fast = true
                inst.components.locomotor:RunForward()
                inst.AnimState:PlayAnimation("heavy_walk_fast_pre")
                inst.sg.mem.footsteps = 0
            elseif oldonenter then
                oldonenter(inst, ...)
            end
        end
    end
    if sg.states.run then
        local oldonenter = sg.states.run.onenter
        sg.states.run.onenter = function(inst, ...)
            if inst.replica.inventory:IsHeavyLifting() and inst:HasTag("tf_strong") and not (inst.replica.rider ~= nil and inst.replica.rider:IsRiding()) then
                inst.sg.statemem.heavy_fast = true
                inst.components.locomotor:RunForward()
                if not inst.AnimState:IsCurrentAnimation("heavy_walk_fast") then
                    inst.AnimState:PlayAnimation("heavy_walk_fast", true)
                end
                inst.sg:SetTimeout(inst.AnimState:GetCurrentAnimationLength() + .5 * FRAMES)
            elseif oldonenter then
                oldonenter(inst, ...)
            end
        end
    end
    if sg.states.run_stop then
        local oldonenter = sg.states.run_stop.onenter
        sg.states.run_stop.onenter = function(inst, ...)
            if inst.replica.inventory:IsHeavyLifting() and inst:HasTag("tf_strong") and not (inst.replica.rider ~= nil and inst.replica.rider:IsRiding()) then
                inst.sg.statemem.heavy_fast = true
                inst.components.locomotor:Stop()
                inst.AnimState:PlayAnimation("heavy_walk_fast_pst")
            elseif oldonenter then
                oldonenter(inst, ...)
            end
        end
    end
end)

-- hook移速组件,吃了蛋白粉的玩家搬重物不掉速
AddComponentPostInit("locomotor", function(self)
    local oldGetSpeedMultiplier = self.GetSpeedMultiplier
    if TheWorld.ismastersim then
        self.GetSpeedMultiplier = function(self, ...)
            if self.inst:HasTag("tf_strong") and not (self.inst.components.rider ~= nil and self.inst.components.rider:IsRiding()) then
                local mult = self:ExternalSpeedMultiplier()
                if self.inst.components.inventory ~= nil then
                    for k, v in pairs(self.inst.components.inventory.equipslots) do
                        if v.components.equippable ~= nil then
                            local item_speed_mult = v.components.equippable:GetWalkSpeedMult()
                            mult = mult * math.max(item_speed_mult, 1)
                        end
                    end
                end
                return mult * (self:TempGroundSpeedMultiplier() or self.groundspeedmultiplier) * self.throttle
            elseif oldGetSpeedMultiplier then
                return oldGetSpeedMultiplier(self, ...)
            end
        end
    else
        self.GetSpeedMultiplier = function(self, ...)
            if self.inst:HasTag("tf_strong") and not (self.inst.replica.rider and self.inst.replica.rider:IsRiding()) then
                local mult = self:ExternalSpeedMultiplier()
                local inventory = self.inst.replica.inventory
                if inventory ~= nil then
                    for k, v in pairs(inventory:GetEquips()) do
                        local inventoryitem = v.replica.inventoryitem
                        if inventoryitem ~= nil then
                            local item_speed_mult = inventoryitem:GetWalkSpeedMult()
                            mult = mult * math.max(item_speed_mult, 1)
                        end
                    end
                end
                return mult * (self:TempGroundSpeedMultiplier() or self.groundspeedmultiplier) * self.throttle
            elseif oldGetSpeedMultiplier then
                return oldGetSpeedMultiplier(self, ...)
            end
        end
    end
end)

-- 兼容棱镜的异种,棱镜相关的代码文件:datafix_legion.lua
if GLOBAL.TF_SETS.ENABLEDMODS["legion"] then
    -- 棱镜专属的异种种子全局表,根据优先级判断是否创建
    if not GLOBAL.rawget(GLOBAL, "TRANS_DATA_LEGION") then -- 对于global来说，不能直接检测是否有某个元素，需要用rawget才行
        GLOBAL.TRANS_DATA_LEGION = {}
    end

    local mapseeds = {
        tf_orange_oversized = {
            swap = { build = "farm_plant_tf_orange", file = "swap_body", symboltype = "3" },
            fruit = "seeds_tf_orange_l",
        },
    }

    for k, v in pairs(mapseeds) do
        GLOBAL.TRANS_DATA_LEGION[k] = v
    end
    mapseeds = nil

    -- 棱镜专属的异种作物的全局表,根据优先级判断是否创建
    if not GLOBAL.rawget(GLOBAL, "CROPS_DATA_LEGION") then
        GLOBAL.CROPS_DATA_LEGION = {}
    end

    local xmult = 1
    local time_crop = 12 * TUNING.TOTAL_DAY_TIME * xmult -- 普通作物一般是5天生长期
    local time_day1 = TUNING.TOTAL_DAY_TIME * xmult
    local time_ripe = time_day1 * 6                      -- 过熟时间默认6天

    -- witheredprefab 代表枯萎时被挖起的产物
    GLOBAL.CROPS_DATA_LEGION.tf_orange = {    -- 橘子异种
        growthmults = { 1.8, 1.5, 1.8, 0.6 }, -- 春夏秋冬:大于1为快,小于1为慢
        regrowstage = 2,
        bank = "crop_tf_orange",
        build = "crop_tf_orange",
        leveldata = {
            { anim = "idle_1", time = time_day1,        deadanim = "dead", witheredprefab = nil },
            { anim = "idle_2", time = time_crop * 0.45, deadanim = "dead", witheredprefab = { "log" } },
            { anim = "idle_3", time = time_crop * 0.55, deadanim = "dead", witheredprefab = { "log" }, bloom = true }, -- bloom 表示开花
            {
                anim = {
                    "idle_4_less", "idle_4_normal", "idle_4_more"
                },
                time = time_ripe,
                deadanim = "dead",
                witheredprefab = { "log", "log" }
            }
        },
        cluster_size = { 1, 1.5 } -- 簇栽动画倍率最低为 1 最高为 1.5
    }
end

-- 兼容棱镜的幻化机制
local dressup_dd_mod = {
    tf_orange_oversized = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_orange_oversized_waxed = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_orange_oversized_rotten = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_strawberry_oversized = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_strawberry_oversized_waxed = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_strawberry_oversized_rotten = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_cabbage_oversized = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_cabbage_oversized_waxed = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_cabbage_oversized_rotten = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_green_pepper_oversized = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_green_pepper_oversized_waxed = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    tf_green_pepper_oversized_rotten = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
}
-- 将以上的幻化数据插入全局变量 DRESSUP_DATA_LEGION,来实现兼容化
if GLOBAL.rawget(GLOBAL, "DRESSUP_DATA_LEGION") then -- 已有变量了(多半是别的模组加的),那就逐一添加数据
    for k, v in pairs(dressup_dd_mod) do
        GLOBAL.DRESSUP_DATA_LEGION[k] = v
    end
else -- 没有变量，那就直接赋值即可
    GLOBAL.DRESSUP_DATA_LEGION = dressup_dd_mod
end
dressup_dd_mod = nil -- 这么大个临时变量，用完就主动清理了吧

-- 调味粉相关,注意配置
if TUNING.TF_SPICES == "Yes" then
    -- 调味后料理额外三维恢复
    AddPrefabPostInitAny(function(inst)
        if not TheWorld.ismastersim then
            return
        end

        if inst:HasTag("spicedfood")
            and inst.components.edible and inst.components.edible.spice and tf_spicedfoods.TF_SPICES[inst.components.edible.spice]
            and inst.components.inventoryitem
        then
            local spicename = string.lower(inst.components.edible.spice)
            if spicename == "spice_tf_konpeito" then
                inst.components.edible.healthvalue = inst.components.edible.healthvalue + 15
                inst.components.edible.hungervalue = inst.components.edible.hungervalue + 15
                inst.components.edible.sanityvalue = inst.components.edible.sanityvalue + 15
            elseif spicename == "spice_tf_sunny_side_up_egg" then
                inst.components.edible.healthvalue = inst.components.edible.healthvalue + 20
                inst.components.edible.hungervalue = inst.components.edible.hungervalue + 60
            elseif spicename == "spice_tf_mayonnaise" then
                inst.components.edible.healthvalue = inst.components.edible.healthvalue + 40
            elseif spicename == "spice_tf_mustard" then
                inst.components.edible.sanityvalue = inst.components.edible.sanityvalue + 33
            elseif spicename == "spice_tf_tomato_sauce" then
                inst.components.edible.hungervalue = inst.components.edible.hungervalue + 40
            elseif spicename == "spice_tf_bacon_bits" then
                inst.components.edible.hungervalue = inst.components.edible.hungervalue + 20
            elseif spicename == "spice_tf_coffee_powder" then
                inst.components.edible.sanityvalue = inst.components.edible.sanityvalue + 10
            elseif spicename == "spice_tf_orange_jam" then
                inst.components.edible.sanityvalue = inst.components.edible.sanityvalue + 20
            elseif spicename == "spice_tf_strawberry_jam" then
                inst.components.edible.healthvalue = inst.components.edible.healthvalue + 20
            end
        end
    end)

    -- 调味后料理替换调味料贴图，但是我们的swapbuild不是spices，必须改成我们自己的动画build
    local OldOverrideSymbol = AnimState.OverrideSymbol
    AnimState.OverrideSymbol = function(self, symbol, swapbuild, swapsymbol, ...)
        if symbol == "swap_garnish" and swapbuild == "spices" and swapsymbol and tf_spicedfoods.TF_SPICES[string.upper(swapsymbol)] then
            swapbuild = "tf_spices"
        end
        return OldOverrideSymbol(self, symbol, swapbuild, swapsymbol, ...)
    end

    -- Mod加载完后给所有食谱添加一遍新调料的料理，以下代码参考了风铃大佬的小穹，风铃大佬牛逼！
    local oldRegisterPrefabs = GLOBAL.ModManager.RegisterPrefabs

    GLOBAL.ModManager.RegisterPrefabs = function(self, ...)
        -- 这个时候 PrefabFiles文件还没有被加载

        for k, v in pairs(cooking.recipes) do
            if k and v and k ~= "portablespicer" then
                tf_spicedfoods.Tf_GenerateSpicedFoods(v)
            end
        end
        -- 添加新的调味料理食谱
        for k, v in pairs(tf_spicedfoods.TfGetNewRecipes()) do
            AddCookerRecipe("portablespicer", v)
        end
        oldRegisterPrefabs(self, ...)
    end
end

--================================================================================================================
--[[ 修改 stewer 组件,使得火锅灶台烹饪出的料理直接添加模组专属调味且是满新鲜度 ]]
--================================================================================================================
local SPICE_SUFFIXES = {
    "_spice_tf_konpeito",
    "_spice_tf_tomato_sauce",
    "_spice_tf_mayonnaise",
    "_spice_tf_mustard"
}

AddComponentPostInit("stewer", function(self)
    -- 保存官方原版的 Harvest 函数
    local _Harvest = self.Harvest

    function self:Harvest(harvester, ...)
        if self.inst.prefab == "tf_cookpot" then
            -- 勋章相关的
            if self.done and harvester ~= nil and self.chef_id == harvester.userid and self.product
                and TUNING.TF_MEDAL_ENABLED and TUNING.TF_COOKPOT == "Yes" and self.inst.upgraded == 2 then
                local cook_medal = harvester.components.inventory and harvester.components.inventory:EquipMedalWithgroupTag("chefMedal")
                if cook_medal then
                    local fuelnum = nil
                    if cook_medal.prefab == "cook_certificate" then
                        fuelnum = 5
                    elseif cook_medal.prefab == "chef_certificate" then
                        fuelnum = 3
                    end
                    -- 消耗耐久
                    if fuelnum ~= nil and cook_medal.components.finiteuses then
                        cook_medal.components.finiteuses:Use(fuelnum)
                        if not RewardToiler(harvester, 0.1) then   -- 天道酬勤
                            SpawnMedalTips(harvester, fuelnum, 10) -- 弹幕提示
                        end
                    end
                end
            end
            -- 自己mod的改动
            if self.done then
                if self.onharvest ~= nil then
                    self.onharvest(self.inst)
                end

                if self.product ~= nil and self.foodstack ~= nil and self.foodstack > 1 then
                    for i = 1, self.foodstack do
                        local loot = SpawnPrefab(self.product)
                        local loot1
                        if loot:HasTag("preparedfood") and TUNING.TF_SPICES == "Yes" and TUNING.TF_COOKPOT == "Yes" and self.inst.upgraded == 2 then
                            local spice_suffix = SPICE_SUFFIXES[math.random(#SPICE_SUFFIXES)]
                            loot1 = SpawnPrefab(self.product .. spice_suffix)
                        else
                            loot1 = SpawnPrefab(self.product)
                        end
                        loot:Remove()
                        if loot1 ~= nil then
                            local recipe = cooking.GetRecipe(self.inst.prefab, self.product)

                            if harvester ~= nil and
                                self.chef_id == harvester.userid and
                                recipe ~= nil and
                                recipe.cookbook_category ~= nil and
                                cooking.cookbook_recipes[recipe.cookbook_category] ~= nil and
                                cooking.cookbook_recipes[recipe.cookbook_category][self.product] ~= nil then
                                harvester:PushEvent("learncookbookrecipe", { product = self.product, ingredients = self.ingredient_prefabs })
                            end

                            local stacksize = recipe and recipe.stacksize or 1
                            if stacksize > 1 then
                                loot1.components.stackable:SetStackSize(stacksize)
                            end

                            if self.spoiltime ~= nil and loot1.components.perishable ~= nil then
                                loot1.components.perishable:SetPercent(1)
                                loot1.components.perishable:StartPerishing()
                            end
                            if harvester ~= nil and harvester.components.inventory ~= nil then
                                harvester.components.inventory:GiveItem(loot1, nil, self.inst:GetPosition())
                            else
                                LaunchAt(loot1, self.inst, nil, 1, 1)
                            end
                        end
                    end
                    self.product = nil
                elseif self.product ~= nil then
                    local loot = SpawnPrefab(self.product)
                    local loot1
                    if loot:HasTag("preparedfood") and TUNING.TF_SPICES == "Yes" and TUNING.TF_COOKPOT == "Yes" and self.inst.upgraded == 2 then
                        local spice_suffix = SPICE_SUFFIXES[math.random(#SPICE_SUFFIXES)]
                        loot1 = SpawnPrefab(self.product .. spice_suffix)
                    else
                        loot1 = SpawnPrefab(self.product)
                    end
                    loot:Remove()
                    if loot1 ~= nil then
                        local recipe = cooking.GetRecipe(self.inst.prefab, self.product)

                        if harvester ~= nil and
                            self.chef_id == harvester.userid and
                            recipe ~= nil and
                            recipe.cookbook_category ~= nil and
                            cooking.cookbook_recipes[recipe.cookbook_category] ~= nil and
                            cooking.cookbook_recipes[recipe.cookbook_category][self.product] ~= nil then
                            harvester:PushEvent("learncookbookrecipe", { product = self.product, ingredients = self.ingredient_prefabs })
                        end

                        local stacksize = recipe and recipe.stacksize or 1
                        if stacksize > 1 then
                            loot1.components.stackable:SetStackSize(stacksize)
                        end

                        if self.spoiltime ~= nil and loot1.components.perishable ~= nil then
                            loot1.components.perishable:SetPercent(1)
                            loot1.components.perishable:StartPerishing()
                        end
                        if harvester ~= nil and harvester.components.inventory ~= nil then
                            harvester.components.inventory:GiveItem(loot1, nil, self.inst:GetPosition())
                        else
                            LaunchAt(loot1, self.inst, nil, 1, 1)
                        end
                    end
                    self.product = nil
                end

                if self.task ~= nil then
                    self.task:Cancel()
                    self.task = nil
                end
                self.targettime = nil
                self.done = nil
                self.spoiltime = nil
                self.product_spoilage = nil

                if self.inst.components.container ~= nil then
                    self.inst.components.container.canbeopened = true
                end

                return true
            end
        else
            local result = _Harvest(self, harvester, ...)
            return result
        end
    end
end)

-- 原版表未指定overridebuild的料理,因为食纪元会把本mod厨具和原版料理两个参数传进去判断得到是mod料理
local cook_pot_food = {
    perogies = true,
    monstertartare = true,
    pepperpopper = true,
    potatosouffle = true,
    guacamole = true,
    nightmarepie = true,
    freshfruitcrepes = true,
    waffles = true,
    trailmix = true,
    bonestew = true,
    ratatouille = true,
    glowberrymousse = true,
    moqueca = true,
    butterflymuffin = true,
    honeynuggets = true,
    jellybean1 = true,
    jellybean2 = true,
    jellybean3 = true,
    flowersalad = true,
    spoiled_food = true,
    unagi = true,
    pumpkincookie = true,
    powcake = true,
    icecream = true,
    stuffedeggplant = true,
    monsterlasagna = true,
    frogfishbowl = true,
    turkeydinner = true,
    fishtacos = true,
    vegstinger = true,
    fruitmedley = true,
    bananapop = true,
    mandrakesoup = true,
    taffy = true,
    voltgoatjelly = true,
    watermelonicle = true,
    kabobs = true,
    jellybean = true,
    gazpacho = true,
    dragonpie = true,
    wetgoop = true,
    mashedpotatoes = true,
    bonesoup = true,
    jammypreserves = true,
    meatballs = true,
    asparagussoup = true,
    ceviche = true,
    salsa = true,
    baconeggs = true,
    dragonchilisalad = true,
    hotchili = true,
    frogglebunwich = true,
    honeyham = true,
    potatotornado = true,
    fishsticks = true,
}

-- Mod加载完后给所有食谱添加一遍新调料的料理，以下代码参考了风铃大佬的小穹，风铃大佬牛逼！
local oldRegisterPrefabs = GLOBAL.ModManager.RegisterPrefabs

GLOBAL.ModManager.RegisterPrefabs = function(self, ...)
    -- 这个时候 PrefabFiles文件还没有被加载

    -- 所有的菜谱都过一遍，把需要添加新料理的食谱都记下来
    for k, v in pairs(cooking.recipes) do
        if k and v and k ~= "portablespicer" then
            -- 添加菜谱到火锅灶台里
            for a, b in pairs(v) do
                if not (b.spice or b.platetype) then -- 要把调味料理排除掉,把有盘子的料理排除掉(暴食的)
                    local newrecipe = shallowcopy(b) -- 浅拷贝一份料理数据
                    if newrecipe == nil then
                        return
                    end
                    newrecipe.no_cookbook = true     -- 不应该显示到食谱书里去
                    newrecipe.cookpot_perishtime = 0 -- 这个锅子里做好的菜不会腐烂
                    -- 用这口锅烹饪料理的时间均小于10秒
                    if type(newrecipe.cooktime) == "number" and newrecipe.cooktime > 0.5 then
                        newrecipe.cooktime = 0.5
                    end
                    if newrecipe.mod and newrecipe.mod == "tf" then
                        newrecipe.priority = newrecipe.priority + 200
                    end
                    -- 兼容食纪元的桌子
                    if newrecipe.basename ~= nil and cook_pot_food[newrecipe.basename] then
                        newrecipe.overridebuild = "cook_pot_food"
                        b.overridebuild = "cook_pot_food"
                    elseif newrecipe.name ~= nil and cook_pot_food[newrecipe.name] then
                        newrecipe.overridebuild = "cook_pot_food"
                        b.overridebuild = "cook_pot_food"
                    end
                    AddCookerRecipe("tf_cookpot", newrecipe)
                end
            end
        end
    end
    oldRegisterPrefabs(self, ...)
end

-- 火锅灶台兼容智能锅mod
if AddCookingPot ~= nil then
    AddCookingPot("tf_cookpot")
end

-- 兼容自动做饭mod
local cookware_morphs = {
    portablecookpot = {    -- 种类 [cookpot, portablecookpot, portablespicer]
        tf_cookpot = true, -- 厨具的预制体名称
    }
}
local AUTO_COOKING_COOKWARES = GLOBAL.rawget(GLOBAL, "AUTO_COOKING_COOKWARES") or {}
GLOBAL.AUTO_COOKING_COOKWARES = AUTO_COOKING_COOKWARES
for base, morphs in pairs(cookware_morphs) do
    AUTO_COOKING_COOKWARES[base] = shallowcopy(morphs, AUTO_COOKING_COOKWARES[base])
end

-- hook所有玩家
AddPlayerPostInit(function(inst)
    if not TheWorld.ismastersim then
        return inst
    end
    if not inst.components.tf_apple then
        inst:AddComponent("tf_apple")
    end
end)

-- 牛牛添加挤奶组件
AddPrefabPostInit("beefalo", function(inst)
    if not TheWorld.ismastersim then
        return inst
    end
    if not inst.components.tf_milker then
        inst:AddComponent("tf_milker")
    end
end)
